﻿using Hopscotch.Common.Contracts.AppService;
using Hopscotch.Domain.Common;
using Hopscotch.Domain.Common.StateTracking;
using Hopscotch.Presentation.Common;
using Hopscotch.Presentation.Common.Commands;

namespace Hopscotch.Presentation.Common.Commands
{
    public class NewEntityCommand<T, TKey> : CommandBase, ICommandBase
        where T : DomainBase<TKey>
        where TKey : struct
    {
        private readonly IToolViewModel<T, TKey> toolViewModel;

        public NewEntityCommand(IToolViewModel<T, TKey> toolViewModel)
        {
            this.toolViewModel = toolViewModel;
        }

        public bool CanExecute(object parameter)
        {
            return toolViewModel.ToolEditMode == ToolEditMode.None;
        }

        public void Execute(object parameter)
        {
            toolViewModel.ToolEditMode = ToolEditMode.New;
            toolViewModel.SetModel(null);            
        }
    }
}
